package vv.wicket;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

public class first extends WebPage {
	private int counter = 0;
	final private Label label;
	
	public first() {
    	Model<Integer> model = new Model<Integer>() {
            public Integer getObject() {
                return counter++;
            }
        };
        
//        label = new Label("counter", model);
        label = new Label("counter", new PropertyModel<Integer>(this, "counter"));
        label.setOutputMarkupId(true);
        
        add(new AjaxFallbackLink("link") {
            @Override
        	public void onClick(AjaxRequestTarget target) {
                counter++;
            	if (target != null) {
                    // target is only available in an Ajax request
                    target.addComponent(label);
                }
            }
        });
        add(label);
    }
}